import java.util.*;
import java.util.concurrent.PriorityBlockingQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-04-21
 * Time: 19:51
 */
class Student implements Comparable<Student> {
    public int age;
    public String name;
    @Override
    public int compareTo(Student o) {
        //比较对象的大小关系，返回只有正负数和0
        return o.age - this.age;
    }

    @Override
    public boolean equals(Object o) {
        //判断是否相等，返回true或者false
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(age, name);
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }
}
//比较器
class AgeComparator implements Comparator<Student> {
    @Override
    public int compare(Student o1, Student o2) {
        return o2.age - o1.age;
    }
}
class NameComparator implements Comparator<Student> {
    @Override
    public int compare(Student o1, Student o2) {
        return o2.name.compareTo(o1.name);
    }
}
public class Test {
    public static void main(String[] args) {
        Queue<Integer> queue = new PriorityQueue<>();
        queue.offer(11);
        queue.offer(2);
        queue.offer(3);
        System.out.println(queue.poll());
    }
    public static void main3(String[] args) {
        Student student1 = new Student();
        student1.name = "ahangsan";
        student1.age = 10;

        Student student2 = new Student();
        student2.name = "zhangsan";
        student2.age = 9;

        PriorityQueue<Student> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(student1);
        priorityQueue.offer(student2);
        Student ret = priorityQueue.poll();
//        System.out.println(ret);

        AgeComparator ageComparator = new AgeComparator();
        PriorityQueue<Student> priorityQueue1 = new PriorityQueue<>(ageComparator);
        priorityQueue1.offer(student1);
        priorityQueue1.offer(student2);
//        System.out.println(priorityQueue1.poll());

        NameComparator nameComparator = new NameComparator();
        PriorityQueue<Student> priorityQueue2 = new PriorityQueue<>(nameComparator);
        priorityQueue2.offer(student1);
        priorityQueue2.offer(student2);
        System.out.println(priorityQueue2.poll());
    }
    public static void main4(String[] args) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(11);
        priorityQueue.offer(2);
        priorityQueue.offer(3);


    }
    public static void main5(String[] args) {
        Student student1 = new Student();
        student1.name = "zhangsan";
        student1.age = 10;

        Student student2 = new Student();
        student2.name = "zhangsan";
        student2.age = 9;
//        System.out.println(student1.compareTo(student2));
//        System.out.println(student1.equals(student2));
        AgeComparator ageComparator = new AgeComparator();
        System.out.println(ageComparator.compare(student1,student2));
        NameComparator nameComparator = new NameComparator();
        System.out.println(nameComparator.compare(student1,student2));
    }
    public static void main1(String[] args) {
        Heap heap = new Heap();
        int[] arr = {27, 15, 19, 18, 28, 34, 65,49,25,37};
        heap.createHeap(arr);
        heap.poll();

    }

    public static void main2(String[] args) {
//        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
//        priorityQueue.offer(1);
//        priorityQueue.offer(2);
//        priorityQueue.offer(-1);
//        System.out.println(priorityQueue.poll());//默认是小根堆
//
//
//        List<Integer> list = new ArrayList<>();
//        list.add(111);
//        list.add(2222);
//        Queue<Integer> priorityQueue2 = new PriorityQueue<>(list);
//        System.out.println(priorityQueue2.poll());


//        priorityQueue2.offer(1);
//        PriorityBlockingQueue<Integer> priorityBlockingQueue = new PriorityBlockingQueue<>();//线程安全
        Queue<Student> queue = new PriorityQueue<>();
        queue.offer(new Student());
        queue.offer(new Student());
        //当旺优先级队列中存储自定义类型时，这个类型一定要实现comparable接口

//        queue.offer(null);
    }
}
